#include <stdio.h>
#include <math.h>

int matix[][5] = {
        {1, 1, 0, 1, 1},
        {0, 1, 1, 1, 0},
        {1, 0, 1, 1, 1},
        {1, 1, 0, 0, 1},
        {1, 1, 0, 1, 1}
    };

int matixSize = 5;
int matixColSize[] = {5};

int leftMax (int i, int j) {
    if (i >= matixSize || j >= matixColSize[0]) {
        return 0;
    }
    if (matix[i][j] == 0) {
        return 0;
    } else {
        return 1 + leftMax(i, j + 1);
    }
}

int downMax (int i, int j) {
    if (i >= matixSize || j >= matixColSize[0]) {
        return 0;
    }
    if (matix[i][j] == 0) {
        return 0;
    } else {
        return 1 + downMax(i + 1, j);
    }
}

int ldMax (int i, int j) {
    if (i >= matixSize || j >= matixColSize[0]) {
        return 0;
    }
    if (matix[i][j] == 0) {
        return 0;
    } else {
        return 1 + ldMax(i + 1, j + 1);
    }
}

int rdMax (int i, int j) {
    if (i >= matixSize || j >= matixColSize[0] || j < 0) {
        return 0;
    }
    if (matix[i][j] == 0) {
        return 0;
    } else {
        return 1 + rdMax(i + 1, j - 1);
    }
}


int main () {
    int res = 0;
    for (int i = 0; i < matixSize; ++i) {
        for (int j = 0; j < matixColSize[0]; ++j) {
            int left = leftMax(i, j);
            int down = downMax(i, j);
            int ld = ldMax(i, j);
            int rd = rdMax(i, j);
            res = fmax(res, left);
            res = fmax(res, down);
            res = fmax(res, ld);
            res = fmax(res, rd);
            printf("%d %d %d\t", left, down, ld);
        }
        printf("\n");
    }

    printf("furthest is %d\n", res);
    return 0;
}